/*
 * @Author: asushiye
 * @Date: 2020-07-03 08:51:09
 * @Commit: file content
 */
import { Injectable } from '@angular/core';
import { AfMessageService, gw_code_g } from '@core';
import { _HttpClient } from '@delon/theme';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class CgExcelService {
  fileType = 'cg-table-list';

  constructor(
    private http: _HttpClient,
    private msg: AfMessageService
  ) {}

  public get httpClient(): _HttpClient {
    return this.http;
  }

  // 查询上传队列
  public query(fileName: string): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/queue/query1?business=${this.fileType}&fileName=${fileName}`);
  }

  // 查询列历史上传队列
  public queryHistory(fileName: string, business: string): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/queue/history/query?business=${business}&fileName=${fileName}`);
  }

  // 归档到历史表中
  public archive(id: any): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/queue/archive/${id}`);
  }
  // 删除历史表中
  public delete(id: any): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/queue/history/delete/${id}`);
  }

  // 下载文件
  public getDownloadFileUrl(id: any, history: boolean): string {
    return `${gw_code_g}/excel/download/${id}?history=${history}`;
  }

  // 查看dbMeta对象
  public generatedbMetaJson(id: any, history: boolean): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/generate/db/meta/${id}?history=${history}`);
  }

  // 生成脚本
  public generateScript(id: any, dbType: any, history: boolean): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/generate/ddl/script/generate/${id}?dbType=${dbType}&history=${history}`);
  }

  // 执行脚本，生成表结构
  public executeScript(id: any, dbType: any, dbSource: any, history: boolean): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/generate/ddl/script/execute/${id}?dbType=${dbType}&dbSource=${dbSource}&history=${history}`);
  }

  // 下载Spring-JPA代码
  public downloadJpaZip(id: any, history: boolean): string {
    return `${gw_code_g}/excel/generate/jpa/code/zip/${id}?history=${history}`;
  }

  // 生成jpa代码
  public generateJpaList(id: any, history: boolean): Observable<any> {
    return this.http.get(`${gw_code_g}/excel/generate/jpa/code/list/${id}?history=${history}`);
  }

  // 数据库脚本日志
  public getQueryDbScriptLogUrl(): string {
    return `${gw_code_g}/db/script/log/query`;
  }
}
